/*
yiiCActiveFormPlus = (function(){
	
});
*/

/*
jQuery yii CActiveFormPlus
*/
(function(jQuery){
	"use strict";
	var cActiveFormPlusPool = {}
	var cActiveFormPlus = function(){
		this.formElement = {}
		this.setElementComponent = function (attribute,component,componentFun){
			if(!this.formElement.hasOwnProperty(attribute)){
				this.formElement[attribute] = {}
			}
			this.formElement[attribute][component] = componentFun;
		}
		
		this.addSetValue = function(attribute,elementFun){
			this.setElementComponent(attribute,'setValue',elementFun);
		}

		this.addGetValue = function(attribute,elementFun){
			this.setElementComponent(attribute,'getValue',elementFun);
		}
		
		this.setData = function(attribute,value,element){
			if(this.formElement.hasOwnProperty(attribute)){
				this.formElement[attribute].setValue(value,element);
			}
		}
		
		this.getData = function(attribute,element){
			return this.formElement[attribute].getValue(attribute,element);
		}
	}
	jQuery.fn.cwidgetCActiveFormPlus = function(options){
		var domElements = $(this);
		var _selector = domElements.selector;
		if(typeof cActiveFormPlusPool[_selector] == 'undefined'){
			cActiveFormPlusPool[_selector] = new cActiveFormPlus();
		}
		var _return;
		domElements.each(function(){
			var domElement = $(this);
			for(var optionName in options){
				switch(optionName){
					case 'addSetValue':
						for(var element in options['addSetValue']){
							cActiveFormPlusPool[_selector].addSetValue(element,options['addSetValue'][element]);
						}
					break;
					case 'addGetValue':
						for(var element in options['addGetValue']){
							cActiveFormPlusPool[_selector].addGetValue(element,options['addGetValue'][element]);
						}
					break;
					case 'set':
						for(var attribute in options['set']){
							cActiveFormPlusPool[_selector].setData(attribute,options['set'][attribute],domElement.find("[attribute='"+attribute+"']"));
						}
					break;
					case 'get':
						_return = cActiveFormPlusPool[_selector].getData(options['get'],domElement.find("[attribute='"+options['get']+"']"));
					break;
					 
				}
			}	
		});
		return _return;
	}
})(jQuery);